package com.cold.demo.template.test;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * 知苗预约
 */
public class GrabHPVForXF_ZMYY {

    public static final Logger log = LoggerFactory.getLogger(GrabHPVForXF_ZMYY.class.getSimpleName());

    private static volatile Map<String, List<String>> headers;

    private static Map<String, List<String>> generateHeader() {
        if (headers != null) {
            return headers;
        }
        String sql = "Host: cloud.cn2030.com\n" +
                "Connection: keep-alive\n" +
                "Cookie: \n" +
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat\n" +
                "content-type: application/json\n" +
                "zftsl: 0929d008545379463a1802cbf6b79a6c\n" +
                "Referer: https://servicewechat.com/wx2c7f0f3c30d99445/84/page-frame.html\n" +
                "Accept-Encoding: gzip, deflate, br";

        String[]                  split = sql.split("\n");
        Map<String, List<String>> res   = new HashMap<>();
        for (String s : split) {
            String       sp    = ": ";
            String       key   = s.split(sp)[0];
            String       value = s.replace(key + sp, "");
            List<String> list  = res.computeIfAbsent(key, k -> new ArrayList<>());
            list.add(value);
        }
        headers = res;
        return headers;
    }


    public static void main(String[] args) throws InterruptedException {
        generateHeader();

        queryYiYuan();

    }

    private static void queryYiYuan() {
        Map<String,Object> params = new HashMap<>();
        params.put("act","CustomerList");
        params.put("city","[\"\",\"\",\"\"]");
        params.put("lat","30.64242");
        params.put("lng","104.04311");
        params.put("id","0");
        params.put("cityCode","0");// 城市
        params.put("product","1");// 九价的代号
        String url = "https://cloud.cn2030.com/sc/wx/HandlerSubscribe.ashx";
        HttpRequest get = HttpUtil.createGet(url);
        get.header(headers);
        get.form(params);
        HttpResponse execute = get.execute();
        String body = execute.body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        System.out.println(jsonObject);
    }
}
